﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using LSEntity;
using LSUtility;
using MathematicsData;
using MathematicsEntity;

namespace MathematicsBLL
{
    public static class KSBBLL
    {
        public static string CourseXMLPath(WebPageConfig webPageConfig)
        {
            return HttpContext.Current.Server.MapPath(webPageConfig.ViewPath + KSBWebConfig.CourseXMLName);
        }

        public static CourseCollection CourseGetList(WebPageConfig webPageConfig)
        {
            return BaseTool.XmlToList<CourseCollection>(CourseXMLPath(webPageConfig));
        }

        public static CourseCollection CourseCollection
        {
            get { return MathematicsCache<CourseCollection>.MemoryGet(KSBWebConfig.CourseCacheKey); }
        }

        /// <summary>
        /// 练习数据
        /// </summary>
        /// <returns></returns>
        public static List<TestReportDataEntity> TestReportData()
        {
            return KSBData.TestReportData();
        }

        /// <summary>
        /// 生成练习报表数据
        /// </summary>
        /// <param name="sources"></param>
        /// <returns></returns>
        public static List<ChartShowEntity<String, int, String>> TestReport(this List<TestReportDataEntity> sources)
        {
            var result = new List<ChartShowEntity<String, int, String>>();
            foreach (var ksbDoEntity in sources)
            {
                result.AddRange(new[]
                                    {
                                        new ChartShowEntity<string, int, String>
                                            {
                                                XField = "练习人数" ,
                                                YField = ksbDoEntity.PeopleCount,
                                                GroupField =ksbDoEntity.ClassName,
                                            }, 
                                            new ChartShowEntity<string, int, String>
                                            {
                                                XField =  "平均得分",
                                                YField = ksbDoEntity.AveragePoint,
                                                GroupField =ksbDoEntity.ClassName,
                                            },
                                            new ChartShowEntity<string, int, String>
                                            {
                                                XField ="平均正确率",
                                                YField = ksbDoEntity.AverageRight,
                                                GroupField = ksbDoEntity.ClassName ,
                                            }
                                    });
            }
            return result;
        }
    }
}
